package ua.tach.shortl.logic;

import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.math.Vector2;

public class RailStraight extends Rail{
	public RailStraight(Switch left, Switch right , Vector2 sh, float r) {
		super(left, right, sh, r);
	}

	public RailStraight(Point sh, float r, boolean paid) {
		super(sh, r, paid);
	}

	public Point getSecond() {
		switch((int)rotation) {
		case 0:
			return new Point(shift.x+1, shift.y);
		case 90:
			return new Point(shift.x, shift.y-1);
		case 180:
			return new Point(shift.x+1, shift.y);
		default:
			return new Point(shift.x, shift.y+1);
		}
	}

	public void render (GL10 gl) {
		super.render(gl, 1);
	}

	// For train moving
	public float getRailSize () {
		return BASERAILSIZE;
	}

	public boolean isCorrectPos(RailPosition p) {
		return !(p.pos<0 || p.pos>= BASERAILSIZE);
	}

	@Override
	public boolean getCoordinate(RailPosition pos) {
		RailStraight.calcCoord(shift, rotation, pos);
		return true;
	}

	public int getRailDir (Switch s) {
		return 2;
	}

	public static void calcCoord(Point pp, float a, RailPosition pos) {
		pos.rotate = (pos.dir)?a:a+180f;
		float dif = pos.pos / BASERAILSIZE;
		float dif1 = (pos.dir)?dif:1-dif;
		if(a == 0) {
			pos.renderCoord.y = pp.y;
			pos.renderCoord.x = pp.x + dif1;
		} else {
			pos.renderCoord.x = pp.x;
			pos.renderCoord.y = pp.y - dif1;
		}
	}
}
